<?php
include "conf.inc";
header("Content-Type:text/html; charset="._CHARSET);
$op = isset($_GET["o"]) ? trim($_GET["o"]) : "";
$category_handler = xoops_getmodulehandler("category");
$group_handler = xoops_getmodulehandler("group");
switch ($op) {
    case "access":
        $group_id = isset($_POST["id"]) ? intval($_POST["id"]) : 0;
        $group_obj = $group_handler->getGroup($group_id);
        if( !is_object($xoopsUser) ) {
            return ;
        }
        if ( $group_obj ) {
            if ( true === $group_handler->updateFootprintUids($group_id,$xoopsUser->uid()) ) {
                $footprint_handler = xoops_getmodulehandler("footprint");
                $params = array(
                    'group_id' => (int)$group_id,
                    'uid' => (int)$xoopsUser->uid(),
                    'footprint_display' => 1
                );
                $footprint_handler->updateFields($params);
            }
        }
        break;
        
    case "remove":
    case "join":
        $group_id = isset($_POST["id"]) ? intval($_POST["id"]) : 0;
        $group_obj = $group_handler->getGroup($group_id);
        if( !is_object($xoopsUser) ) {
            return ;
        }
        $asJoin = ($op == "join") ? true : false;
        if ( $group_obj ) {
            if ( true === $group_handler->updateMemberUids($group_id,$xoopsUser->uid(),$asJoin) ) {
                $memb_handler = xoops_getmodulehandler("memb");
                $params = array(
                    'group_id' => (int)$group_id,
                    'uid' => (int)$xoopsUser->uid()
                );
                if ( true === $asJoin ) {
                    $memb_handler->setMember($params);
                } else {
                    $memb_handler->removeMember($params);
                }
            }
        }
        exit;
        break;
        
    case "c":
    case "create":
        include XOOPS_ROOT_PATH."/class/template.php";
        $xoopsTpl = new XoopsTpl();
        
        $group_obj = $group_handler->create();
        $cat_arg = $category_handler->getCatSelect();
		include(dirname(__FILE__)."/include/form.us.group.php");
		$xoopsTpl->display("db:groups_group_create.html");
        break;
        
    default:
        die("not param");
}

?>